﻿function getFormData(selector, isStringify = false) {
    var data = {};
    var t = $(selector).serializeArray();
    $.each(t, function () {
        data[this.name] = this.value;
    });
    if (isStringify) return JSON.stringify(data);
    return data;
}

function minimize() {
    window.chrome.webview.hostObjects.winform.Minimize();
}

function maximize() {
    window.chrome.webview.hostObjects.winform.Maximize();
}

function shutdown() {
    window.chrome.webview.hostObjects.winform.Close();
}

$(function () {
    var clicks = 0, delay = 400;

    $(".header .bar").mousedown(function (e) {
        e.preventDefault();
        clicks++;
        setTimeout(function () {
            clicks = 0;
        }, delay);

        if (clicks === 2) {
            clicks = 0;
            window.chrome.webview.hostObjects.winform.Maximize();
            return;
        } else {
            window.chrome.webview.hostObjects.winform.StartDrag();
        }
    });

    $(".header .bar").mouseup(function (e) {
        window.chrome.webview.hostObjects.winform.EndDrag();
    });
});
